package com.endpoint.book.controller;


import com.endpoint.book.service.BookCommentService;
import com.endpoint.book.vo.MemberCommentVo;
import com.endpoint.common.utils.JwtTokenUtil;
import com.endpoint.common.utils.ResultBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 * 小说评论表 前端控制器
 * </p>
 *
 * @author Jack_Li
 * @since 2024-07-03
 */
@RestController
@RequestMapping("/book/bookComment")
public class BookCommentController {

    @Autowired
    private BookCommentService bookCommentService;

    @PostMapping("comment")
    public ResultBean comment(@Valid @RequestBody MemberCommentVo memberCommentVo
            , @RequestHeader("Authorization") String token){
        //从token 中获取用户id
        Long userid = JwtTokenUtil.getUserIdFromToken(token);
        memberCommentVo.setUserId(userid);
        ResultBean resultBean = bookCommentService.saveComment(memberCommentVo);
        return resultBean;
    }
}

